<?php
/**
 * Created By base
 * Author: Virus
 * Date: 2020/3/17
 * Time: 17:58
 */

namespace app\common\model\mysql;


class AdminLog extends BaseModel
{
    public static function record()
    {
        $admin_id   = session('uid');
        $admin_id   = isset($admin_id) ? $admin_id : 0;
        $controller = request()->controller();
        $action     = request()->action();
        $ip         = request()->ip();
        $useragent  = substr(request()->server('HTTP_USER_AGENT'), 0, 255);

        self::create(
            [
                'admin_id'   => $admin_id,
                'controller' => $controller,
                'action'     => $action,
                'ip'         => $ip,
                'useragent'  => $useragent,
            ]
        );
    }

    public function admin()
    {
        return $this->belongsTo(Admin::class, 'admin_id', 'id')->setEagerlyType(0);
    }
}